<template>
    <div>
        <!-- 轮播图 -->
        <el-carousel :interval="4000" type="card" height="400px">
            <el-carousel-item v-for="(item, index) in carouselImg" :key="index">
                <img :src="item.itemImg" width="100%" height="100%" />
            </el-carousel-item>
        </el-carousel>
        <!-- /轮播图 -->
        <!-- 好房推荐 -->
        <div class="title">好房推荐</div>
        <div class="recommendBox">
            <div v-for="(item, index) in recommendHouseList" :key="index" class="recommendHouse" @click="getInfo(item)">
                <img :src="item.imageUrl" :alt="item.address" />
                <div class="recommendHouseInfo">
                    <el-avatar size="large" :src="item.imageUrl" class="recommendUserAvatar"></el-avatar>
                    <!-- 展示用户名 -->
                    <span style="margin-left: -40px;" name="userName">
                        {{ text }}
                    </span>
                    <div style="float: right; margin-right: 2px;">月租:{{ item.price }}RMB/月</div>
                </div>
            </div>
        </div>
        <!-- /好房推荐 -->
    </div>
</template>

<script>
export default {
    name: "IIndex",
    components: {
    },
    data() {
        return {
            carouselImg: [
                { itemImg: require("../../assets/carousel_1.jpg"), itemTitle: "" },
                { itemImg: require("../../assets/carousel_2.jpg"), itemTitle: "" },
                { itemImg: require("../../assets/carousel_3.jpg"), itemTitle: "" },
                { itemImg: require("../../assets/carousel_4.jpg"), itemTitle: "" },
                { itemImg: require("../../assets/carousel_5.png"), itemTitle: "" },
                { itemImg: require("../../assets/carousel_6.jpg"), itemTitle: "" },
            ],
            text:"可可今天不吃肉",
            recommendHouseList: []
        };
    },
    methods: {
        handleSelect(key, keyPath) {
            console.log(key, keyPath);
        },
        getInfo(item) {
            this.$router.push("/yunye/houseinfo?id=" + item.id);
        },
        initRecommendHouseList() {
            let self = this;
            this.axios({
                url: "http://127.0.0.1:8000/api/house/queryRHouse",
                method: "get",
            }).then(function (response) {
                self.recommendHouseList = response.data;
            }).catch(function (error) {
            });
        }
    },
    mounted: function () {
        this.initRecommendHouseList();
    },
};
</script>

<style scoped>
.el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    line-height: 160px;
    position: relative;
    z-index: 1;
}

.el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 200px;
    margin: 0;
}

.el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
}

/* 房屋推荐部分 */
.title {
    font-size: 28px;
    height: 50px;
    line-height: 50px;
}

/* /房屋推荐部分 */
</style>